//
//  PaperAnswerView.m
//  ZYOnlineSchool
//
//  Created by 毕武侠 on 2017/3/7.
//  Copyright © 2017年 bwx. All rights reserved.
//

#import "PaperAnswerView.h"

@interface PaperAnswerView ()

@property (nonatomic, strong) PaperAnswerModel *model;
@property (nonatomic, strong) PaperAnswerScrollView *answerView;

@end

@implementation PaperAnswerView
@dynamic answerView;

- (void)setupConfigure {
    [super setupConfigure];
    
    self.answerView = [[PaperAnswerScrollView alloc] initWithFrame:self.frame];
    @weakify(self)
    self.answerView.selectBlock = ^(NSUInteger index) {
        @strongify(self)
        if ([self.delegate respondsToSelector:@selector(responActionWithData:)]) {
            [self.delegate responActionWithData:@{@"action" : @"select", @"index" : [NSNumber numberWithUnsignedInteger:index]}];
        }
    };
    
    self.answerView.contentBlock = ^(NSString *content){
        @strongify(self)
        if ([self.delegate respondsToSelector:@selector(responActionWithData:)]) {
            [self.delegate responActionWithData:@{@"action" : @"answer", @"contet" : content}];
        }
        
    };
    
    
    
    [self addSubview:self.answerView];
    
    
#if TGT_XBGK
    self.answerView.backgroundColor = [UIColor colorWithHexString:@"f4f4f4"];
#endif
}

- (void)bindModel:(PaperAnswerModel *)model {
    _model = model;
    
    self.showMaterial = model.showMaterial;
    
    [self.answerView bindModel:model];
    
    if (model.showMaterial == YES) {
        self.answerView.top = 121+SCREEN_WIDTH / 17;
        self.answerView.height = self.height - 121 - SCREEN_WIDTH / 17;
        [self setupViewFrame:YES];
        self.materialView.textLayout = model.materialLayout;
    } else {
        self.answerView.top = 0;
        self.answerView.height = self.height;
    }
}

#pragma mark - PaperCollectionCellProtocol
- (void)didActionWithData:(NSDictionary *)data {
    if ([data objectForKey:@"user_content"]) {
        [self.answerView setAnswerContent:data[@"user_content"]];
        return;
    }
    
    NSUInteger index = [data[@"index"] integerValue];
    PaperOptionType type = [data[@"type"] integerValue];
    [self.answerView setOptionIndex:index withType:type];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
